package com.google.code.swingonfire.showcase.helpers.gradients;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JPanel;

import com.google.code.swingonfire.utility.Gradient;
import com.google.code.swingonfire.utility.interpolation.Interpolation;
import com.google.code.swingonfire.utility.interpolation.Interpolations;

import static com.google.code.swingonfire.utility.Colors.*;
import static java.awt.Color.*;

public class GradientPanel extends JPanel
{

    private static final long serialVersionUID = 6992183408972779600L;

    private Gradient gradient;

    public GradientPanel()
    {
        super();

        setOpaque(false);

        Color color = ORANGE;
        gradient =
            Gradient.start(blendTo(color, WHITE, 0.9)).length(5).color(brighter(color, 0.2)).fraction(1)
                .color(brighter(color, 0.05), color).fraction(1).color(darker(color, 0.1)).length(5)
                .end(blendTo(color, BLACK, 0.25));
    }

    @Override
    protected void paintComponent(Graphics graphics)
    {
        Graphics2D g = (Graphics2D) graphics;

        Color color = ORANGE;
        gradient =
            Gradient.start(brighter(color, 0.2)).length(2).color(brighter(color, 0.0)).fraction(Interpolations.slowing(), 10, 0.5)
                .color(WHITE, BLACK).fraction(Interpolations.accelerating(), 10, 0.5)
                .color(darker(color, 0.0)).length(2).end(darker(color, 0.5));

        //        Color color = brighter(Color.BLUE, 0.5);
        //        Paint paint =
        //            Gradient.start(color).fraction(0.5).color(WHITE).length(2).color(BLACK).fraction(0.05)
        //                .color(GRAY).fraction(0.5).end(WHITE).toVerticalPaint(getHeight());
        //        Paint paint =
        //            Gradient.start(blendTo(color, WHITE, 0.9)).length(5).color(brighter(color, 0.2)).fraction(1)
        //                .color(brighter(color, 0.05), color).fraction(1).color(darker(color, 0.1)).length(5)
        //                .end(blendTo(color, BLACK, 0.25)).toPaint(new Point2D.Double(0, 0), new Point2D.Double(0, getHeight()));

        //        Paint paint =
        //            Gradient.start(blendTo(color, WHITE, 0.5)).length(2).color(color).fraction(0.05).color(darker(color, 0.02))
        //                .fraction(0.05).color(blendTo(darker(color, 0.05), WHITE, 0.5)).fraction(0.20)
        //                .color(blendTo(darker(color, 0.1), WHITE, 0.1), darker(color, 0.1)).fraction(0.15).color(darker(color, 0.1))
        //                .fraction(0.15).color(color).length(2).end(blendTo(color, BLACK, 0.5)).toVerticalPaint(getHeight());

        g.setPaint(gradient.toVerticalPaint(getHeight()));
        g.fillRect(0, 0, getWidth(), getHeight());

        super.paintComponent(graphics);
    }

    @Override
    public void paint(Graphics graphics)
    {

        super.paint(graphics);
    }

}
